﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

public partial class Spa_quan :WeiPage
{
    MembershipCardBO mbo = new MembershipCardBO();
    CardUserBO cbo = new CardUserBO();
    MerchantsBO mer = new MerchantsBO();
    CardToUseBO tbo = new CardToUseBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["code"] != null)
        {
            try
            {
                string url = string.Format(@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + GetAppid() + "&secret=" + GetSecret() + "&code={0}&grant_type=authorization_code", Request.QueryString["code"].ToString());
                string token = PostRequest(url);
                if (token.Contains("7200"))
                {
                    string[] b = token.Split('\"');
                    Session["FromUserName"] = b[13];
                    Session["ToUserName"] = GetAppid();
                }
            }
            catch (Exception)
            {

            }
        }
        if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
        {
            string user = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
            string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
            Session["FromUserName"] = user;
            Session["ToUserName"] = user2;
            List<MembershipCard> list = new List<MembershipCard>();
            list = mbo.GetModelList("1=1 and  type=2 ");
            //            lbCard2.Text = "";
            foreach (MembershipCard card in list)
            {

                ul.InnerHtml += string.Format(@"<li>
      <em><kbd class='tequan'></kbd>&nbsp;券</em>
       <span><i class='xiala'></i></span><strong>{0}</strong>
       <bdo>{1}</bdo>
      </li>
      <ol>
     
     {2}
      </ol>", card.Title, DateTime.Parse(card.CreateDate.ToString()).ToString("yyyy-MM-dd"), card.Explain);
            }

        }
    }
}